package com.nhii.base.common.LayoutManagement;

import android.content.Context;
import android.view.View;

import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.core.BasePopupView;
import com.lxj.xpopup.enums.PopupPosition;
import com.lxj.xpopup.impl.InputConfirmPopupView;
import com.lxj.xpopup.impl.PartShadowPopupView;
import com.lxj.xpopup.interfaces.OnInputConfirmListener;

/**
 * author : Alex
 * e-mail : xys9786@outlook.com
 * date   : 2020/5/68:32
 * desc   :  XPopup 统一初始化类
 * version: 1.0
 */
public class XPopupManagement {

    /**
     * 右弹布局
     * @param context 上下文
     * @param flag   //启用状态栏阴影
     * @param flag1 //启用阴影背景
     * @param view  布局
     * @return
     */
    public static BasePopupView initRightPop(Context context, boolean flag, boolean flag1, BasePopupView view){
        return  new XPopup.Builder(context)
                .popupPosition(PopupPosition.Right)//右边
                .hasStatusBarShadow(flag)
                .hasShadowBg(flag1)
                .asCustom(view)
                .show();
    }


    /**
     * 向上弹出布局
     * @param context 上下文
     * @param flag   //启用状态栏阴影
     * @param flag1 //启用阴影背景
     * @param view  布局
     * @return
     */
    public static BasePopupView initButtomtPop(Context context, boolean flag, boolean flag1, BasePopupView view){
        return  new XPopup.Builder(context)
                .popupPosition(PopupPosition.Bottom)
                .hasStatusBarShadow(flag)
                .hasShadowBg(flag1)
                .asCustom(view)
                .show();
    }
  //

    /**
     * 中间弹框  带有edit
     * @param context 上下文
     * @return
     */
    public static InputConfirmPopupView initInputContent(Context context,
                                                         String title,
                                                         String content,
                                                         String inputcontent,
                                                         String hint,OnInputConfirmListener onInputConfirmListener){

     return new XPopup.Builder(context)
                //.dismissOnBackPressed(false)
                .autoOpenSoftInput(true)
                .autoFocusEditText(false) //是否让弹窗内的EditText自动获取焦点，默认是true
                .isRequestFocus(false)
                //.moveUpToKeyboard(false)   //是否移动到软键盘上面，默认为true
                .asInputConfirm(title, content, inputcontent, hint, onInputConfirmListener)
                .bindLayout(com.nhii.base.common.R.layout.public_xpopup_center_impl_confirm);


    }



    /**
     * 向下弹出布局
     * @param context 上下文
     * @return
     */
    public static BasePopupView initTopPop(Context context, PartShadowPopupView customPartShadowPopupView, View v){
        return  new XPopup.Builder(context)
                .atView(v)

                .isCenterHorizontal(true)
                .autoOpenSoftInput(false)
                .dismissOnTouchOutside(true)
                .asCustom(customPartShadowPopupView)
                ;

    }
    /**
     * 向下弹出布局
     * @param context 上下文
     * @return
     */
    public static BasePopupView initTopPop(Context context, PartShadowPopupView customPartShadowPopupView, View v, int y){
        return  new XPopup.Builder(context)
                .atView(v)
                .offsetY(y)
                .isCenterHorizontal(true)
                .autoOpenSoftInput(false)
                .dismissOnTouchOutside(true)
                .asCustom(customPartShadowPopupView)
                ;

    }
}
